<?php echo $this->fetch('header.html'); ?>
<div id="main" class="w-full">
<div id="page-cart" class="mb20">
   <div class="w step step1 mt10 clearfix">
      <span class="fs14 strong fff">1.查看购物车</span>
      <span class="fs14 strong">2.确认订单信息</span>
      <span class="fs14 strong">3.付款</span>
      <span class="fs14 strong">4.确认收货</span>
      <span class="fs14 strong">5.评价</span>
   </div>
   
   <div class="cartbox w mt20 mb10">
      <div class="amount">
         
      </div>
      <div class="w title clearfix">
         <span class="col-desc">店铺商品</span>
         <span>价格</span>
          
          <span>税费</span>
          
         <span>数量</span>
         <span>小计</span>
         <span>操作</span>
      </div>
      <div class="content">
         <?php $_from = $this->_var['carts']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }; $this->push_vars('store_id', 'cart');if (count($_from)):
    foreach ($_from AS $this->_var['store_id'] => $this->_var['cart']):
?>
         <div class="store-each" data-storeid="<?php echo $this->_var['store_id']; ?>">
            <div class="store-name mt10"><input type="checkbox" checked='checked' class="checkall"/>店铺：<a href="<?php echo url('app=store&id=' . $this->_var['store_id']. ''); ?>"><?php echo htmlspecialchars($this->_var['cart']['store_name']); ?></a></div>
            <?php $_from = $this->_var['cart']['goods']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }; $this->push_vars('', 'goods');$this->_foreach['fe_goods'] = array('total' => count($_from), 'iteration' => 0);
if ($this->_foreach['fe_goods']['total'] > 0):
    foreach ($_from AS $this->_var['goods']):
        $this->_foreach['fe_goods']['iteration']++;
?>
            <dl class="goods-each clearfix" id="cart_item_<?php echo $this->_var['goods']['rec_id']; ?>">
			<dd><input type="checkbox" checked='checked' value="<?php echo $this->_var['goods']['rec_id']; ?>" class="checkitem" data-subtotal="<?php echo $this->_var['goods']['subtotal']; ?>"/></dd>
               <dd class="pic"><a class="block" href="<?php echo url('app=goods&id=' . $this->_var['goods']['goods_id']. ''); ?>" target="_blank"><img src="<?php echo $this->_var['goods']['goods_image']; ?>" alt="<?php echo htmlspecialchars($this->_var['goods']['goods_name']); ?>" width="80" height="80" /></a></dd>
               <dd class="desc">
                  <p><a href="<?php echo url('app=goods&id=' . $this->_var['goods']['goods_id']. ''); ?>" target="_blank"><?php echo htmlspecialchars($this->_var['goods']['goods_name']); ?></a></p>
                  <span class="f66"><?php echo $this->_var['goods']['specification']; ?></span>
               </dd>
               
               <dd class="price">
                   <?php if ($this->_var['goods']['goods_type'] != GOODS_TYPE_NORMAL): ?><p class="old_price"><?php echo price_format($this->_var['goods']['goods_old_price']); ?></p><?php endif; ?>
                   <p class="now_price"><?php echo price_format($this->_var['goods']['price']); ?></p>
                   <?php if ($this->_var['goods']['goods_type'] != GOODS_TYPE_NORMAL): ?><p class="goods_type">(<?php echo call_user_func("goods_type_status",$this->_var['goods']['goods_type']); ?>)</p><?php endif; ?>
               </dd>
                
                <dd class="price">
                    <p class="now_price"><?php echo price_format($this->_var['goods']['tax_price']); ?></p>
                </dd>
                
               <dd class="quantity">
                  <a class="decrease" href="javascript:void(0)" alt="减少" onclick="decrease_quantity(<?php echo $this->_var['goods']['rec_id']; ?>);">-</a>
                  <input class="" id="input_item_<?php echo $this->_var['goods']['rec_id']; ?>" value="<?php echo $this->_var['goods']['quantity']; ?>" orig="<?php echo $this->_var['goods']['quantity']; ?>" changed="<?php echo $this->_var['goods']['quantity']; ?>" onkeyup="change_quantity(<?php echo $this->_var['store_id']; ?>, <?php echo $this->_var['goods']['rec_id']; ?>, <?php echo $this->_var['goods']['spec_id']; ?>, this);" type="text" />
                  <a class="increase" href="javascript:void(0)" alt="增加" onclick="add_quantity(<?php echo $this->_var['goods']['rec_id']; ?>);">+</a>
               </dd>
               <dd class="subtotal fs14 strong" id="item<?php echo $this->_var['goods']['rec_id']; ?>_subtotal"><?php echo price_format($this->_var['goods']['subtotal']); ?></dd>
                
                <dd class="handle" style="width:120px;">
                <!--<dd class="handle" style="width:160px;">-->
                
                   <a class="move" href="javascript:;" onclick="move_favorite(<?php echo $this->_var['store_id']; ?>, <?php echo $this->_var['goods']['rec_id']; ?>, <?php echo $this->_var['goods']['goods_id']; ?>);">加入收藏夹</a>
                   <br />
                   <a class="del" href="javascript:;" onclick="drop_cart_item(<?php echo $this->_var['store_id']; ?>, <?php echo $this->_var['goods']['rec_id']; ?>);">删除</a>
               </dd>
            </dl>
            <?php endforeach; endif; unset($_from); ?><?php $this->pop_vars();; ?>
            <div class="cart-amount mt10 w auto mb10 clearfix">
               <div class="btn-amount">
                  <p>
                     <span>商品总价：</span>
                     <strong class="price fs14 strong mr20"  id="cart<?php echo $this->_var['store_id']; ?>_amount"><?php echo price_format($this->_var['cart']['amount']); ?></strong>
                  </p>
               </div>
            </div>
         </div>
         <?php endforeach; endif; unset($_from); ?><?php $this->pop_vars();; ?>
      </div>
   </div>
    <div class="cartbox">
        <div class="total_amount">
            <div class="toolbar w">
                <a href="javascript:go_to_order()" class="submit_btn">填写并确认订单</a>
            </div>
        </div>
    </div>
   <div class="w interest mt20">
      <div class="title border fs14 padding5 f66 strong"><span class="arr"></span>你可能感兴趣的商品</div>
      <div class="content border border-t-0 clearfix">
         <?php $_from = $this->_var['interest']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }; $this->push_vars('', 'goods');if (count($_from)):
    foreach ($_from AS $this->_var['goods']):
?>
         <dl class="float-left">
           <dt><a href="<?php echo url('app=goods&id=' . $this->_var['goods']['goods_id']. ''); ?>" target="_blank"><img width="160" height="160" src="<?php echo $this->_var['goods']['default_image']; ?>" /></a></dt>
           <dd class="desc"><a href="<?php echo url('app=goods&id=' . $this->_var['goods']['goods_id']. ''); ?>" target="_blank"><?php echo sub_str(htmlspecialchars($this->_var['goods']['goods_name']),50); ?></a></dd>
           <dd class="price clearfix"><em><?php echo $this->_var['goods']['price']; ?></em><span>最新成交<?php echo $this->_var['goods']['sales']; ?>笔</span></dd>
           <dd class="service"></dd>
         </dl> 
         <?php endforeach; endif; unset($_from); ?><?php $this->pop_vars();; ?>
      </div>
   </div>
</div>
</div>
<script>
    $(function(){
            /* 全选 */
    $('.checkall').click(function(){
        var _self = this;
        $(this).parents('.store-each').find('.checkitem').each(function(){
            if (!this.disabled)
            {
                $(this).attr('checked', _self.checked);
            }
        });
        $(this).attr('checked', this.checked);
    });
    $(".content input[type=checkbox]").change(function(){
        $(".store-each").each(function(){
            var subtotal=0;
            $(this).find('.checkitem:checked').each(function(){
                var price=parseFloat($(this).attr('data-subtotal'));
                subtotal=ForDight(subtotal+price,2);
            });
            var store_id=$(this).attr('data-storeid');
            $(this).find('#cart'+store_id+'_amount').text(price_format(subtotal));
        });
        
    });
    })
    function go_to_order(){
                    if ($('.checkitem:checked').length == 0) {
                return false;
            }

            var items = '';
            $('.checkitem:checked').each(function() {
                items += this.value + ',';
            });
            items = items.substr(0, (items.length - 1));

            var uri =  'index.php?app=order&goods=cart&batch=1&rec_ids=' + items;
            window.location.href=uri;return;
    }
    //四舍五入函数
function   ForDight(Dight,How)  
{  
            Dight   =   Math.round   (Dight*Math.pow(10,How))/Math.pow(10,How);  
            return   Dight;  
}  
</script>
<?php echo $this->fetch('server.html'); ?>
<?php echo $this->fetch('footer.html'); ?>